home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 43.zip / Sources C- WorkDisk V.adf / ak / ak3.c < prev    next >
C/C++ Source or Header  |  1987-02-14  |  5KB  |  240 lines

  1. /* enkel deze includes nodig voor soundproductie */
  2. #include "hardware/custom.h"
  3. #include "stdio.h"
  4.  
  5. #include <exec/memory.h>
  6.  
  7. #include <exec/types.h>
  8. #include <intuition/intuition.h>
  9. #include <graphics/sprite.h>
  10.  
  11. struct Preferences MyPrefs;
  12. struct RastPort *rp;
  13. struct IntuitionBase *IntuitionBase;
  14. struct GfxBase *GfxBase;
  15. struct IntuiMessage *msg;
  16. unsigned short color[3];
  17. int red[3], green[3], blue[3];
  18.  
  19. #define NUM          6
  20. #define SPRHEIGHT       16
  21. #define WORDSPERSPR     (2 * SPRHEIGHT + 4)
  22.  
  23. struct NewWindow windef = {
  24.         0,0, 640, 75,
  25.         2, 3,
  26.     FOLLOWMOUSE|MOUSEBUTTONS,
  27.         REPORTMOUSE | WINDOWDRAG | ACTIVATE|SMART_REFRESH,
  28.         NULL, NULL,
  29.         (UBYTE *) "   BAMIGA SECTOR ONE PROUDLY PRESENTS  :  <<<<<<>  AMIGA  KARATE  !  <>>>>>>   ",
  30.         NULL, NULL, 0, 0, 0, 0,
  31.         WBENCHSCREEN
  32. };
  33.  
  34. struct SimpleSprite     spr[NUM];
  35. struct Window   *win;
  36. struct ViewPort *vp;
  37. UWORD           *sprbuf;
  38. UWORD           *sprites[NUM];
  39.  
  40. LONG filesize,s1,s2,per;
  41. char *filename;
  42. short *sndbuffer, *AllocMem();
  43.  
  44. main()
  45. {
  46. int i,j;
  47.  
  48.  
  49. /* aanroep van sound routine */
  50. per = 280;
  51. filename = "UB40";
  52. filesize = 85620;
  53. MakeSound();
  54.  
  55. openstuff ();
  56. ClearMenuStrip(win);
  57.  
  58.  
  59. color[1] = MyPrefs.color17;
  60. color[2] = MyPrefs.color18;
  61. color[3] = MyPrefs.color19;
  62.  
  63. for (i = 1; i <=3; i++)
  64. {
  65. red[i] = (color[i] >> 8) & 0x0F;
  66. green[i] = (color[i] >> 4) & 0x0F;
  67. blue[i] = color[i] & 0x0F;
  68. }
  69.  
  70. for (i = 17; i < 31; i = i + 4)
  71. {
  72. SetRGB4(vp, i, red[1], green[1], blue[1]);
  73. SetRGB4(vp, i+1, red[2], green[2], blue[2]);
  74. SetRGB4(vp, i+2, red[3], green[3], blue[3]);
  75. }
  76.  
  77.         setupsprites ();
  78.  
  79.         for (i=0; i<NUM; i++) {
  80.                 if (GetSprite (&spr[i], (long) i+1) < 0)
  81.                         die ("Sprite allocation failed.");
  82.                 spr[i].x = (win->MouseX + win->LeftEdge + MyPrefs.XOffset);
  83.                 spr[i].y = (win->MouseY + win->TopEdge + MyPrefs.YOffset - 1);
  84.                 spr[i].height = SPRHEIGHT;
  85.                 ChangeSprite (vp, &spr[i], sprites[i]);
  86.         }
  87.  
  88.  
  89.  
  90.      for(;;) {
  91.  
  92.                 if (msg = GetMsg (win->UserPort))
  93.                 {
  94.                  ReplyMsg (msg);
  95.                  if (msg->Class == MOUSEBUTTONS)
  96.                  {
  97.                   while(msg=GetMsg(win->UserPort)) ReplyMsg(msg);
  98.                   custom.dmacon = 0x0003;
  99.                   closestuff();
  100.                   exit();
  101.                  }
  102.             }
  103.                 
  104.  
  105.                 for (i=NUM-1; i>=0; i--) 
  106.               {
  107.         for(j=0;j<2;j++)WaitTOF();
  108.         spr[i].x = (win->MouseX + win->LeftEdge + MyPrefs.XOffset);
  109.         spr[i].y = (win->MouseY + win->TopEdge + MyPrefs.YOffset - 1);
  110.         ChangeSprite (vp, &spr[i], sprites[i]);
  111.             }
  112.            }
  113. }
  114.  
  115. openstuff ()
  116. {
  117. IntuitionBase = OpenLibrary ("intuition.library", 0);
  118.  
  119.     /* Geez, guys, what if Intuition isn't here?  Who cares?  We're
  120.        probably all dead anyways, if this happens... */
  121.  
  122. GfxBase = OpenLibrary ("graphics.library", 0);
  123.  
  124.     /* Ya, sure, you've pulled the Graphics.Library ROM out, right? */
  125.  
  126.         if (!(win = OpenWindow (&windef)))
  127.                 die ("No memory for window");
  128.  
  129. GetPrefs(&MyPrefs, sizeof(struct Preferences));
  130.  
  131.         vp = ViewPortAddress (win);
  132.         rp = win.RPort;
  133.  
  134. }
  135.  
  136. closestuff ()
  137. {
  138.         int i;
  139.  
  140.  
  141.         if(sndbuffer)
  142.           FreeMem(sndbuffer,filesize);
  143.  
  144.         for (i=0; i<NUM; i++)
  145.                 if (spr[i].num)
  146.                         FreeSprite ((long) spr[i].num);
  147.  
  148.         if (sprbuf)
  149.                 FreeMem (sprbuf,2L * WORDSPERSPR * NUM);
  150.         if (win)
  151.                 CloseWindow (win);
  152.         if (GfxBase)
  153.                 CloseLibrary (GfxBase);
  154.         if (IntuitionBase)
  155.                 CloseLibrary (IntuitionBase);
  156. }
  157.  
  158. die (str)
  159. char *str;
  160. {
  161.         puts (str);
  162.         closestuff ();
  163.         exit (100);
  164. }
  165.  
  166. setupsprites ()
  167. {
  168. /* This is what I stole.  Boy, I hope it wasn't copyrighted... */
  169.  
  170.         UWORD *cw;  
  171.         UWORD *ballp; 
  172.         int frame, scan;
  173.  
  174.         if (!(sprbuf = AllocMem(2L * WORDSPERSPR * NUM, MEMF_CHIP)))
  175.                 die ("Can't allocate sprite buffer.");
  176.  
  177.         cw = sprbuf;    /* current position at top of buffer */
  178.         for (frame=0; frame<NUM; frame++) {
  179.                 sprites[frame] = cw;
  180.                 *cw++ = 0;              /* poscntl */
  181.                 *cw++ = 0;
  182.                 ballp = &MyPrefs.PointerMatrix[0]; 
  183.                 for (scan=0; scan<SPRHEIGHT; scan++) {
  184.                         *cw++ = *ballp++;
  185.                         *cw++ = *ballp++;
  186.                 }
  187.                 *cw++ = 0;      /* termination */
  188.                 *cw++ = 0;
  189.         }
  190. }
  191.  
  192.  
  193. MakeSound()
  194. {
  195. LoadSound();
  196. PlaySong();
  197. }  
  198.  
  199. LoadSound()
  200. {
  201. FILE *fopen(), *fp;
  202. SHORT *ptr;
  203. LONG i;
  204.  
  205. sndbuffer = AllocMem(filesize,MEMF_CHIP);
  206. ptr = sndbuffer;
  207.  
  208. custom . dmacon = 0x0003;
  209. fp = fopen(filename,"r");
  210. if (fp == NULL) return(0);
  211.  
  212. s1 = 0; s2 =filesize;
  213. for (i=0; i<s1; i++)
  214.     getc(fp);
  215.  
  216. for (i=s1/2; i<s2/2; i++)
  217.     {
  218.     *ptr++ = getc(fp)*256 + getc(fp);
  219.     }
  220.  
  221. fclose (fp);
  222. }
  223.  
  224. PlaySong()
  225. {
  226. custom . aud[0].ac_ptr = (UWORD *)sndbuffer;
  227. custom . aud[0].ac_len = s2/2-s1/2;
  228. custom . aud[0].ac_per = per;
  229. custom . aud[0].ac_vol = 64;
  230.  
  231. custom . aud[1].ac_ptr = (UWORD *)sndbuffer;
  232. custom . aud[1].ac_len = s2/2-s1/2;
  233. custom . aud[1].ac_per = per;
  234. custom . aud[1].ac_vol = 64;
  235.  
  236. custom . dmacon = 0x8203;
  237. }
  238.  
  239.  
  240.